        TITL DAI FIRMWARE 2E316-2E406  V1.1
        ORG   :E316
*
*
*
*******************
* SET CURSOR MODE *
*******************
*
* The format of cursor info is 1 byte cursor type
* and 1 byte of information.
* If the type = 0, the cursor flashes in colour.
* The info is a mask which is exored with the
* colour byte for that character to flash it.
* If the type = 1, the cursor alternates between
* the actual character and the one in the info.
*
* If flash entry is never called, cursor will be
* steady in the alternate colour (type 0) or per-
* manently the alternate character (type 1).
*
* Entry: HL points to new cursor info.
* Exit:  All registers preserved.
*
SCURM   PUSH  PSW
        PUSH  B
        PUSH  D
        PUSH  H
        LDA   COL1      Get current screen mode
        RAR             Char mode ?
        CC    CURDEL    Then delete current cursor
        MOV   A,M       Get new cursor type
        STA   CURSH     Store it in pointer
        INX   H
        MOV   A,M       Get new cursor info
        STA   CURTYP    Store it in pointer
 REM
* Entry from CURSET:
 REM
SCM10   CC    CURFL     Flash cursor once if in
 REM char mode
        JMP   XRET      Popall, ret
*
**************
* SET CURSOR *
**************
*
* Sets some cursor on the screen. Does not delete
* a previous cursor. The screen must already be
* in a character mode.
* Gets the contents of the cursor position address
* and stores it in the pointers.
*
* Entry: HL: Address new cursor position.
* Exit:  All registers preserved.
*
CURSET  PUSH  PSW
        PUSH  B
        PUSH  D
        PUSH  H
        PUSH  H
        MOV   D,M       Get contents addr pointed at
 REM by new cursor
        DCX   H
        DCX   H
        DCX   H
        MOV   E,M       Get colour byte of this addr
        POP   H
        CALL  SPT00     Store contents and colour
 REM byte in cursor pointers
        NOP 
        NOP 
        STC             CY=1
        JMP   SCM10     Flash cursor, popall, ret
*
****************
* FLASH CURSOR *
****************
*
* Flashes the cursor once if in char mode,
* otherwise does nothing.
*
* Entry: None.
* Exit:  All registers preserved.
*
*SCURI
CURFL   PUSH  PSW
        PUSH  H
        LHLD  CURSOR    Get cursor pos addr
        MOV   A,H
        ORA   L         Check if addr is 0000
        JZ    CFL10     Abort if no cursor
        LDA   CURSH     Get cursor type
        ORA   A         Check type
        LDA   CURTYP    Get cursor info
        JNZ   CFL20     Jump if char type
 REM
* If 'colour' type:
 REM
        DCX   H         )
        DCX   H         ) Get addr colour byte
        DCX   H         )
        XRA   M         Exor mask with colour byte
CFL05   MOV   M,A       And reload colour byte
CFL10   POP   H
        POP   PSW
        RET 
 REM
* If 'char' type:
 REM
CFL20   CMP   M         Check contents screen loc
CFL30   MOV   M,A       Move cursor info in loc
        JNZ   CFL10     Abort if contents screen
 REM loc is changed now
        LDA   CURMOD    Else: get contents scrn loc
        JMP   CFL05     Store it in this loc
*
*****************
* DELETE CURSOR *
*****************
*
* Deletes the current cursor. Loads the address
* pointed at by the cursor with the data stored
* in RAM (0076/77).
* Routine valid for character modes only.
*
* Entry: None.
* Exit:  All registers preserved.
*
CURDEL  PUSH  PSW
        PUSH  B
        PUSH  D
        PUSH  H
        LHLD  CURSV     Get contents cursor loc
        XCHG            in DE
        LHLD  CURSOR    Get cursor pos addr
        PUSH  H         Save it on stack
        LXI   H,:0000
        SHLD  CURSOR    Move cursor to addr 0000
        POP   H         Restore cursor pos addr
        MOV   A,H
        ORA   L         Check if addr is 0000
        JZ    CDL10     Abort if no cursor
        MOV   M,D       Load data into screen loc
 REM pointed at by cursor
        DCX   H
        DCX   H
        DCX   H
        MOV   M,E       Load colourbyte into loc
 REM pointed at
CDL10   JMP   XRET      Popall, ret
*
***************************
* GET CHARACTER FROM LINE *
***************************
*
* Returns a character from some position on
* the current line.
*
* Entry: C: Line position of required character.
*           (max. legal value = 219).
* Exit:  A: Required character (car.ret if at
*           or past cursor).
*        BCDEHLF preserved.
*
SFETC   PUSH  B
        PUSH  D
        PUSH  H
        PUSH  PSW
        LXI   H,:0086   Total nr. of bytes/line
        LDA   ERRCOD    Get number extended lines
        CALL  HLMUL     Calc total nr of bytes
 REM (HL=A*HL)
        XCHG            in DE
        LHLD  LNSTR     Get addr line mode byte
 REM current line
        DAD   D         Calc start of line on screen
        LXI   D,:FFEA
        DAD   D         End indent area
        XCHG            in DE
        MVI   A,:F9     1st bytes on line not
 REM useable
        ADD   C         Add pos of required char on
 REM line
        PUSH  PSW
        MVI   B,:00
        JNC   SFC20     Jump if in 1st 7 positions
        DCR   B
SFC10   SUI   :35       60 useable positions/line
        INR   B         Count nr of extended lines
        JNC   SFC10     Jump if not on this line
SFC20   MOV   A,B       Nr of extensions in A
        LXI   H,:FFE4   Nr of not used bytes/line
        CALL  HLMUL     ) Add-ons for line ends
        DAD   D         )
        POP   PSW       Restore pos of char on line
        MOV   E,A       into E
        CMC 
        SBB   A
        MOV   D,A       D=char.count - nr of idents
        XCHG
        DAD   H         Pos *2 due to colour bytes
        XCHG
        CALL  SUBDE     Calc pos of reqd char
        XCHG            Addr in DE
        LHLD  CURSOR    Get cursor pos addr
        CALL  COMP      Compare it with addr of char
        MVI   A,:0D     Car.ret in A
        JNC   SFC30     If on or after cursor
        LDAX  D         Get character from line
SFC30   MOV   H,A       Save it temporarily
        POP   PSW       Restore flags
        MOV   A,H       Get character in A
        POP   H
        POP   D
        POP   B
        RET 
*
***************
* CHANGE MODE *
***************
*
* Change the mode of the screen.
*
* Entry: A: Code new mode.
* Exit:  ABCDEHL preserved.
*        CY=0: OK.
*        CY=1: Insufficient room for mode.
*
SSETM   STC             CY=1
        PUSH  PSW
        PUSH  B
        PUSH  D
        PUSH  H
        CPI   :FF       Mode 0 ?
        CZ    SSM0      Then set up mode 0 screen
        CNZ   SSMG      Else: Set up screen for
 REM other modes
        JC    STM10     Jump if no room available
        LHLD  SCE       Get end of screen
        PUSH  D
        LXI   D,:0010   Nr of bytes in trailer
        DAD   D         Get 1st addr trailer area
        POP   D         Get addr 1st colour
        MVI   B,:0F     Depth of blank
        CALL  SSUBL     Init trailer area
        LHLD  FFB       Get 1st free byte
        ORA   A         Set flags on scrn mode byte
        CALL  SMKRM     Perform mem. management
        STA   COL1      Store current screen mode
        JMP   XRCC      Popall (CY=0), ret
 REM
* If error:
 REM
STM10   JMP   XRET      Popall (CY=1), ret
*
*
*
        UNL
COL1    EQU   :009D
CURSH   EQU   :0074
CURTYP  EQU   :0075
XRET    EQU   :E138
SPT00   EQU   :D68D
CURSOR  EQU   :0072
CURMOD  EQU   :0077
CURSV   EQU   :0076
ERRCOD  EQU   :007B
HLMUL   EQU   :EB46
LNSTR   EQU   :0078
SUBDE   EQU   :E6F2
COMP    EQU   :E6FB
SSM0    EQU   :E407
SSMG    EQU   :E43E
SCE     EQU   :008E
SSUBL   EQU   :E5FC
FFB     EQU   :0084
SMKRM   EQU   :E5A6
XRCC    EQU   :E12E
        LST
        END 
